from django.shortcuts import render
from rest_framework.generics import ListAPIView
from .models import Banner, Nav
from .serializers import BannerSerializer, NavSerializer
from skylark_api.settings import constans
# Create your views here.
"""
功能：获取显示的轮播图列表 
实现思路：
1.指定过滤条件,必须是is_show=True, is_delete=False
2.排序：-orders降序，-id 从小到大就是升序，从大到小，降序
3.数量限制：固定显示5张

"""
class BannerView(ListAPIView):
    queryset = Banner.objects.filter(is_show=True, is_delete=False).order_by('-orders', '-id')[:constans.BANNER_LENGTH]
    serializer_class = BannerSerializer
    pass



class NavListView(ListAPIView):
    """顶部导航的列表"""
    queryset = Nav.objects.filter(is_show=True, is_deleted=False, position=1).order_by("orders")
    serializer_class = NavSerializer


class NavFooterView(ListAPIView):
    """底部导航的列表"""
    queryset = Nav.objects.filter(is_show=True, is_deleted=False, position=2).order_by("orders")
    serializer_class = NavSerializer